package com.ruitu.mall_98_1.product.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.beanu.arad.Arad;
import com.beanu.arad.base.my_base.base_list.ListBaseAdapter;
import com.beanu.arad.base.my_base.base_list.SuperViewHolder;
import com.beanu.arad.utils.Logg;
import com.ruitu.mall_98_1.R;
import com.ruitu.mall_98_1.product.activity.ProductDetailActivity;
import com.ruitu.router_module.bean.EventModel;
import com.ruitu.router_module.bean.product.Product;
import com.ruitu.router_module.bean.product.ShopDetail;

public class ShopClassifyAdapter extends ListBaseAdapter<ShopDetail.Classify> {
    public ShopClassifyAdapter(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.pro_shop_item_classify_list;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        TextView tv_name = holder.getView(R.id.tv_name);
        TextView tv_more = holder.getView(R.id.tv_more);
        RecyclerView rcv_pro = holder.getView(R.id.rcv_pro);

        final ShopDetail.Classify c = mDataList.get(position);
        tv_name.setText(c.getTypeName());

        if (null == c.getGoods() || c.getGoods().size() <= 0) {
            tv_more.setVisibility(View.GONE);
        }

        ProductListAdapter adapter = new ProductListAdapter(mContext);
        adapter.type = 2;
        rcv_pro.setLayoutManager(new GridLayoutManager(mContext, 2) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
        rcv_pro.setAdapter(adapter);
        adapter.setDataList(c.getGoods());

        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View itemView, int position) {
                Product product = c.getGoods().get(position);
                Intent intent = new Intent(mContext, ProductDetailActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("product", product);
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });
        tv_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Arad.bus.post(new EventModel(18113051));
            }
        });
    }
}
